package com.draven.mybatis.mapping;

import com.draven.mybatis.session.DravenSqlSession;
import org.apache.ibatis.binding.MapperProxy;
import org.apache.ibatis.session.SqlSession;


import java.io.Serializable;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.InvocationHandler;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

public class DravenMapperProxy<T> implements InvocationHandler, Serializable {

  DravenSqlSession sqlSession;
  private final Class<T> mapperInterface;
  private final Map<Method, MapperMethodInvoker> methodCache;

  public DravenMapperProxy(DravenSqlSession sqlSession, Class<T> mapperInterface, Map<Method, MapperMethodInvoker> methodCache) {
    this.sqlSession = sqlSession;
    this.mapperInterface = mapperInterface;
    this.methodCache = methodCache;
  }


  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
      return method.invoke(this, args);
  }

  interface MapperMethodInvoker {
    Object invoke(Object proxy, Method method, Object[] args, DravenSqlSession sqlSession) throws Throwable;
  }


}
